//
//  ZH_MineAddressViewController.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/24.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_MineAddressViewController.h"
#import "ZH_MIneAddressTableViewCell.h"
#import "ZH_AddNewAddressViewController.h"
@interface ZH_MineAddressViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,weak)UITableView *tableView;
@property (nonatomic,weak)UIButton *button;
@end

@implementation ZH_MineAddressViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUserInterface];
}

- (void)initUserInterface{
    self.navigationItem.title = @"地址管理";
    self.view.backgroundColor = kCommonBackgroudColor;
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.height.mas_equalTo(FITSCALE(50));
    }];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view);
        make.left.equalTo(self.view).offset(FITSCALE(11));
        make.right.equalTo(self.view).offset(FITSCALE(-11));
        make.bottom.equalTo(self.button.mas_top);
    }];
}
#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return FITSCALE(9);
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZH_MIneAddressTableViewCell *cell = [ZH_MIneAddressTableViewCell cellWithTableView:tableView];
    return cell;
}
#pragma mark - private
- (void)addAddress{
    ZH_AddNewAddressViewController *vc = [[ZH_AddNewAddressViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - getter,setter
- (UITableView *)tableView{
    if (!_tableView) {
        UITableView *tableView = [UITableView createTableViewWithDelegateTarget:self];
        tableView.backgroundColor = kCommonBackgroudColor;
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [tableView setCellAutoAdaptationForEstimatedRowHeight:FITSCALE(100)];
        [self.view addSubview:_tableView = tableView];
    }
    return _tableView;
}
- (UIButton *)button{
    if (!_button) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"新增" target:self action:@selector(addAddress)];
        [button setTitleColor:[UIColor colorWithHexString:@"#00C9AE"] forState:UIControlStateNormal];
        button.backgroundColor = [UIColor colorWithHexString:@"#CEECE8"];
        button.titleLabel.font = kFontSize_34;
        [self.view addSubview:_button = button];
    }
    return _button;
}


@end
